﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Markup;
using System.Globalization;
using System.Drawing;
using BL.Entity;
using BL.Service;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
using System.Runtime.Remoting.Channels.Tcp;


namespace LTO
{
    public static class Gobalsource
    {
        public static TcpChannel chan;
        public static List<String> listUserLogin;
        public static bool IsAppRunning { get; set; }
        public static string ModeConnection { get; set; }
        public static string UserNameLogin { get; set; }
        public static int UserIDLogin { get; set; }
        public static string Password { get; set; }
        public static int TotalClient { get; set; }
        public static BL.Utiltty utility { get { return new BL.Utiltty(); } }
        public static DateTime PreriodStart { get; set; }
        public static DateTime PreriodEnd { get; set; }
        public static bool IsOnlineMode = false;
        public static MessageViewer2 objChatWin = new MessageViewer2();
        public static List<NumberDTO> GenDummy_3Number(List<NumberDTO> db)
        {
            List<NumberDTO> result = new List<NumberDTO>();
            for (int i = 0; i < 1000; i++)
            {
                string numDummy = i.ToString().PadLeft(3, '0').ToString();
                NumberDTO numberSelect;
                var query = from item in db
                            where item.Number == numDummy
                            select item;
                numberSelect = query.FirstOrDefault();
                if (numberSelect != null)
                {
                    result.Add(numberSelect);
                }
                else
                {
                    numberSelect = new NumberDTO()
                    {
                        Number = numDummy,
                        Over_Price = 0M,
                        Under_Price = 0M,
                        Tod_Price = 0M
                    };
                    result.Add(numberSelect);
                }

            }
            return result;
        }
        public static List<NumberDTO> GenDummy_3NumberTod(List<NumberDTO> db, string numberType)
        {
            List<NumberDTO> result = new List<NumberDTO>();
            string num1;
            string num2;
            string num3;
            string num4;
            string num5;
            string num6;

            for (int i = 0; i < 10; i++)
            {
                for (int j = i; j < 10; j++)
                {

                    for (int k = j; k < 10; k++)
                    {
                        num1 = string.Format("{0}{1}{2}", i, j, k);
                        num2 = string.Format("{0}{2}{1}", i, j, k);
                        num3 = string.Format("{1}{0}{2}", i, j, k);
                        num4 = string.Format("{1}{2}{0}", i, j, k);
                        num5 = string.Format("{2}{1}{0}", i, j, k);
                        num6 = string.Format("{2}{0}{1}", i, j, k);

                        var query = from item in db
                                    where item.Number == num1
                                    || item.Number == num2
                                    || item.Number == num3
                                    || item.Number == num4
                                    || item.Number == num5
                                    || item.Number == num6
                                    select item;
                        if (query.FirstOrDefault() != null)
                        {
                            string Minnum = query.Min(s => s.Number);
                            NumberDTO resultItem = query.Where(n => n.Number == Minnum).FirstOrDefault();
                            resultItem.Number = Minnum;

                            foreach (NumberDTO item in query.ToList())
                            {
                                if (resultItem.Number != item.Number)
                                {
                                    resultItem.Over_Price += item.Over_Price;
                                    resultItem.Under_Price += item.Under_Price;
                                    resultItem.Tod_Price += item.Tod_Price;
                                }


                            }
                            result.Add(resultItem);
                        }
                        else
                        {
                            NumberDTO dummy = new NumberDTO()
                            {
                                Number = num1,
                                NumType = numberType
                                ,
                                Over_Price = 0
                                ,
                                Under_Price = 0
                                ,
                                Tod_Price = 0
                            };
                            result.Add(dummy);
                        }
                    }
                }
            }


            return result;
        }
        public static List<ShowNumberDTO> GenDummy_3NumberTod(List<ShowNumberDTO> db, decimal LimitNum, decimal minSt, decimal minEn)
        {
            List<ShowNumberDTO> result = new List<ShowNumberDTO>();

            if (db.Count() > 0)
            {

                foreach (ShowNumberDTO item in db)
                {
                    if (item.Number.GroupBy(s => s).Count() < 3)
                    {
                        ShowNumberDTO temp = new ShowNumberDTO();

                        temp.Number = item.Number;
                        temp.Price = item.Price;
                        temp.OrgPrice = item.Price;
                        temp.IsDummy = true;
                        temp.LimitPrice = LimitNum;
                        temp.OverSt = minSt;
                        temp.OverEn = minEn;

                        result.Add(temp);
                        // }
                    }
                }

            }

            return result;
        }
        public static List<NumberDTO> GenDummy_2Number(List<NumberDTO> db)
        {
            List<NumberDTO> result = new List<NumberDTO>();
            for (int i = 0; i < 100; i++)
            {
                string numDummy = i.ToString().PadLeft(2, '0').ToString();
                NumberDTO numberSelect;
                var query = from item in db
                            where item.Number == numDummy
                            select item;
                numberSelect = query.FirstOrDefault();
                if (numberSelect != null)
                {
                    result.Add(numberSelect);
                }
                else
                {
                    numberSelect = new NumberDTO()
                    {
                        Number = numDummy,
                        Over_Price = 0M,
                        Under_Price = 0M,
                        Tod_Price = 0M
                    };
                    result.Add(numberSelect);
                }

            }
            return result;
        }
        public static List<NumberDTO> GenDummy_TwinFront(List<NumberDTO> db)
        {
            List<NumberDTO> result = new List<NumberDTO>();
            for (int i = 0; i < 100; i++)
            {
                string numDummy = i.ToString().PadLeft(2, '0').PadRight(3, '-').ToString();
                NumberDTO numberSelect;
                var query = from item in db
                            where item.Number == numDummy
                            select item;
                numberSelect = query.FirstOrDefault();
                if (numberSelect != null)
                {
                    result.Add(numberSelect);
                }
                else
                {
                    numberSelect = new NumberDTO()
                    {
                        Number = numDummy,
                        Over_Price = 0M,
                        Under_Price = 0M,
                        Tod_Price = 0M
                    };
                    result.Add(numberSelect);
                }

            }
            return result;
        }
        public static List<NumberDTO> GenDummy_TwinStretch(List<NumberDTO> db)
        {
            List<NumberDTO> result = new List<NumberDTO>();
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    string numDummy = i.ToString() + "-" + j.ToString();
                    NumberDTO numberSelect;
                    var query = from item in db
                                where item.Number == numDummy
                                select item;
                    numberSelect = query.FirstOrDefault();
                    if (numberSelect != null)
                    {
                        result.Add(numberSelect);
                    }
                    else
                    {
                        numberSelect = new NumberDTO()
                        {
                            Number = numDummy,
                            Over_Price = 0M,
                            Under_Price = 0M,
                            Tod_Price = 0M
                        };
                        result.Add(numberSelect);
                    }
                }


            }
            return result;
        }
        public static List<NumberDTO> GenDummy_2Over(List<NumberDTO> db)
        {
            List<NumberDTO> result = new List<NumberDTO>();
            for (int i = 0; i < 100; i++)
            {
                string numDummy = i.ToString().PadLeft(2, '0').ToString();
                NumberDTO numberSelect;
                var query = from item in db
                            where item.Number == numDummy
                            select item;
                numberSelect = query.FirstOrDefault();
                if (numberSelect != null)
                {
                    result.Add(numberSelect);
                }
                else
                {
                    numberSelect = new NumberDTO()
                    {
                        Number = numDummy,
                        Over_Price = 0M,
                        Under_Price = 0M,
                        Tod_Price = 0M
                    };
                    result.Add(numberSelect);
                }

            }
            return result;
        }
        public static List<NumberDTO> GenDummy_2OverFont(List<NumberDTO> db)
        {
            List<NumberDTO> result = new List<NumberDTO>();
            for (int i = 0; i < 100; i++)
            {
                string numDummy = i.ToString().PadLeft(2, '0').ToString();
                numDummy = numDummy + "-";
                NumberDTO numberSelect;
                var query = from item in db
                            where item.Number == numDummy
                            select item;
                numberSelect = query.FirstOrDefault();
                if (numberSelect != null)
                {
                    result.Add(numberSelect);
                }
                else
                {
                    numberSelect = new NumberDTO()
                    {
                        Number = numDummy,
                        Over_Price = 0M,
                        Under_Price = 0M,
                        Tod_Price = 0M
                    };
                    result.Add(numberSelect);
                }

            }
            return result;
        }
        public static List<NumberDTO> GenDummy_2OverBetween(List<NumberDTO> db)
        {
            List<NumberDTO> result = new List<NumberDTO>();
            for (int i = 0; i < 10; i++)
            {
                string numDummy;
                for (int n1 = 0; n1 < 10; n1++)
                {
                    numDummy = string.Format("{0}-{1}", i, n1);

                    NumberDTO numberSelect;
                    var query = from item in db
                                where item.Number == numDummy
                                select item;
                    numberSelect = query.FirstOrDefault();
                    if (numberSelect != null)
                    {
                        result.Add(numberSelect);
                    }
                    else
                    {
                        numberSelect = new NumberDTO()
                        {
                            Number = numDummy,
                            Over_Price = 0M,
                            Under_Price = 0M,
                            Tod_Price = 0M
                        };
                        result.Add(numberSelect);
                    }
                }
            }
            return result;
        }
        public static List<NumberDTO> GenDummy_1Runing(List<NumberDTO> db, string NumberType)
        {
            List<NumberDTO> result = new List<NumberDTO>();
            for (int i = 0; i < 10; i++)
            {
                string numDummy = i.ToString();
                if (NumberType == EnumLocal.NumberType.Over1Unit || NumberType == EnumLocal.NumberType.Under1unit)
                {
                    if (NumberType == EnumLocal.NumberType.Over1Unit)
                    {
                        numDummy = string.Format("--{0}", numDummy);
                    }
                    else
                    {
                        numDummy = string.Format("-{0}", numDummy);
                    }
                }
                if (NumberType == EnumLocal.NumberType.Over1Decimal || NumberType == EnumLocal.NumberType.Under1Decimal)
                {
                    if (NumberType == EnumLocal.NumberType.Over1Decimal)
                    {
                        numDummy = string.Format("-{0}-", numDummy);
                    }
                    else
                    {
                        numDummy = string.Format("{0}-", numDummy);
                    }
                }
                if (NumberType == EnumLocal.NumberType.Over1Hundred)
                {
                    numDummy = string.Format("{0}--", numDummy);
                }
                NumberDTO numberSelect;
                var query = from item in db
                            where item.Number == numDummy
                            select item;
                numberSelect = query.FirstOrDefault();
                if (numberSelect != null)
                {
                    numberSelect.Number = numDummy;
                    result.Add(numberSelect);
                }
                else
                {
                    numberSelect = new NumberDTO()
                    {
                        Number = numDummy,
                        Over_Price = 0M,
                        Under_Price = 0M,
                        Tod_Price = 0M
                    };
                    result.Add(numberSelect);
                }

            }
            return result;
        }
        public static List<ShowNumberDTO> ConvetNumberShow(List<NumberDTO> db, string numType, decimal limit, decimal OverLimitSt, decimal OverLimitEn)
        {
            List<ShowNumberDTO> result = new List<ShowNumberDTO>();
            ShowNumberDTO numShow;
            foreach (NumberDTO item in db)
            {
                numShow = new ShowNumberDTO()
                {
                    Number = item.Number,
                    OverSt = OverLimitSt,
                    OverEn = OverLimitEn,
                    LimitPrice = limit
                };
                switch (numType)
                {
                    case EnumLocal.NumberConvertShow.Over:
                        numShow.Price = item.Over_Price;
                        numShow.OrgPrice = item.Over_Price;
                        numShow.ColumnNameShow = "Over_Price";
                        break;
                    case EnumLocal.NumberConvertShow.Under:
                        numShow.Price = item.Under_Price;
                        numShow.OrgPrice = item.Under_Price;

                        numShow.ColumnNameShow = "Under_Price";
                        break;
                    case EnumLocal.NumberConvertShow.Tod:
                        numShow.Price = item.Tod_Price;
                        numShow.OrgPrice = item.Tod_Price;

                        numShow.ColumnNameShow = "Tod_Price";
                        break;
                }
                numShow.Over = item.Over_Price;
                numShow.Under = item.Under_Price;
                numShow.Tod = item.Tod_Price;


                result.Add(numShow);
            }

            return result;

        }

        public static IList<T> Clone<T>(this IList<T> listToClone) where T : ICloneable
        {
            return listToClone.Select(item => (T)item.Clone()).ToList();
        }
        public static List<ShowNumberDTO> ConvertToDummy(List<ShowNumberDTO> temp)
        {
            List<ShowNumberDTO> showGroup = new List<ShowNumberDTO>();

            temp.ForEach(n => n.Number = String.Concat(n.Number.OrderBy(c => c)));

            var groupNum = from numDTO in temp
                           group numDTO by numDTO.Number into g
                           select new
                           {
                               Number = g.Key,
                               Price = g.Sum(s => s.Price),
                               OverSt = g.Max(m => m.OverSt),
                               OverEn = g.Max(m => m.OverEn),
                               LimitPrice = g.Max(m => m.LimitPrice),
                               ColumnNameShow = g.Max(m => m.ColumnNameShow),
                               Over = g.Sum(o => o.Over),
                               Under = g.Sum(u => u.Under),
                               Tod = g.Sum(t => t.Tod)
                           };
            foreach (var item in groupNum)
            {
                ShowNumberDTO gItem = new ShowNumberDTO()
                {
                    ColumnNameShow = item.ColumnNameShow,
                    LimitPrice = item.LimitPrice,
                    Number = item.Number,
                    Over = item.Over,
                    Under = item.Under,
                    Tod = item.Tod,
                    OverEn = item.OverEn,
                    OverSt = item.OverSt,
                    Price = item.Price,
                    OrgPrice = item.Price
                };
                showGroup.Add(gItem);
            }
            temp = new List<ShowNumberDTO>();
            temp = showGroup;
            return temp;
        }
        #region :: Print Solution ::
        static double columnWidth = 140;
        static double pageCount = 0;
        static int PageFrom = 1;
        static int PageTo = 1;
        static decimal sum = 0;
        static List<ShowNumberDTO> printDataSource = new List<ShowNumberDTO>();
        public static void PrintReport(List<ShowNumberDTO> datasourceNum, string numType, decimal LimitBuy)
        {


            System.Windows.Controls.PrintDialog printDalog = new System.Windows.Controls.PrintDialog();


            printDalog.UserPageRangeEnabled = true;
            if (printDalog.ShowDialog().Value)
            {
                PageFrom = printDalog.PageRange.PageFrom;
                PageTo = printDalog.PageRange.PageTo;

                FlowDocument doc = CreateFlowDocument(numType, datasourceNum);
                doc.PageWidth = 793;
                doc.PageHeight = 1122;
                doc.PageHeight = printDalog.PrintableAreaHeight;
                doc.PageWidth = printDalog.PrintableAreaWidth;

                IDocumentPaginatorSource idocument = doc as IDocumentPaginatorSource;
                printDalog.PrintDocument(idocument.DocumentPaginator, "");
                //for (int i =  printDalog.PageRange.PageFrom-1; i < printDalog.PageRange.PageTo; i++)
                //{
                //    printDalog.PrintVisual(idocument.DocumentPaginator.GetPage(i).Visual, "PrintingNumber...");

                //}
            }
            MessageBoxResult IsdeletNum = MessageBox.Show("ต้องการลบข้อมูลหรือไม?", "ลบข้อมูล", MessageBoxButton.YesNo, MessageBoxImage.Asterisk, MessageBoxResult.No);
            if (IsdeletNum == MessageBoxResult.Yes)
            {
                tbl_NumberServer Numberservice = new tbl_NumberServer();

                List<ShowNumberDTO> delteNum = new List<ShowNumberDTO>();
                delteNum = datasourceNum.Where(w => w.Price > 0).ToList();
                tbl_NumberServer numSvr = new tbl_NumberServer();
                NumberDTO numselect = new NumberDTO();
                foreach (ShowNumberDTO del in delteNum)
                {
                    decimal dele = del.Price;

                    Numberservice.Addnumber(del.Number, dele, 0, 0, Gobalsource.UserNameLogin, numType, true);
                }


            }

        }
        private static FlowDocument CreateFlowDocument(string NumberType, List<ShowNumberDTO> datasourceNum)
        {
            datasourceNum = datasourceNum.Where(p => p.PriceShow != "0").ToList();
            double calBoxPage = 0;

            double countIndex = 0;
            printDataSource = new List<ShowNumberDTO>();
            if (PageTo != 0)
            {
                if (PageFrom == 1 && PageTo <= 0)
                {
                    printDataSource = datasourceNum.Skip(0).Take((PageFrom) * 200).ToList();

                }
                else if (PageFrom == PageTo && PageFrom == 1)
                {
                    printDataSource = datasourceNum.Skip(0).Take(200).ToList();

                }
                else
                {
                    printDataSource = datasourceNum.Skip((PageFrom - 1) * 200).Take(PageTo * 200).ToList();

                }
            }
            else
            {
                printDataSource = datasourceNum;
            }
            //      printDataSource = datasourceNum;

            pageCount = Math.Ceiling(double.Parse(printDataSource.Count.ToString()) / 200);
            calBoxPage = Math.Ceiling(double.Parse(printDataSource.Count.ToString()) / 100);

            FlowDocument doc = new FlowDocument();
            doc.ColumnWidth = 793;
            doc.FontFamily = new System.Windows.Media.FontFamily("MS Sans Serif");
            doc.FontSize = 14;
            doc.PagePadding = new Thickness(10, 40, 0, 0);
            string headerTxt;
            headerTxt = GetHeader(NumberType);


            double pagecount = 0;
            for (double i = 0; i < pageCount; i++)
            {

                Section page = new Section();
                page.BreakPageBefore = true;
                page.Margin = new Thickness(40, 0, 0, 0);
                for (int innerPage = 1; innerPage <= 2; innerPage++)
                {
                    if (calBoxPage > pagecount)
                    {
                        page.Blocks.Add(GetPageHeader(headerTxt, pagecount));
                        pagecount += 1;
                        page.Blocks.Add(GetTableFroPrint(printDataSource, countIndex));
                        countIndex += 100;
                    }
                }


                doc.Blocks.Add(page);
            }

            Paragraph summary = new Paragraph();
            summary.TextAlignment = TextAlignment.Right;
            summary.FontSize = 14;
            summary.FontWeight = FontWeights.Bold;
            summary.Margin = new Thickness(0, 30, 100, 0);
            sum = printDataSource.Sum(p => p.Price);
            if (sum != 0)
            {
                summary.Inlines.Add(string.Format("ยอดรวม {0:#,#}", sum));
            }
            else
            {
                summary.Inlines.Add(string.Format("ยอดรวม {0}", sum));

            }
            doc.Blocks.Add(summary);

            return doc;
        }

        private static Table GetPageHeader(string headerTxt, double pagecount)
        {
            Table tbHeader = new Table();
            tbHeader.Margin = new Thickness(0, 20, 0, 0);
            TableColumn tbHeadColumn = new TableColumn();
            tbHeadColumn.Width = new GridLength(columnWidth * 4);
            tbHeader.Columns.Add(tbHeadColumn);

            tbHeadColumn = new TableColumn();
            tbHeadColumn.Width = new GridLength(columnWidth);
            tbHeader.Columns.Add(tbHeadColumn);

            TableRowGroup tbRowGroup = new TableRowGroup();
            TableRow tbRow = new TableRow();
            TableCell cell1 = new TableCell();
            TableCell cell2 = new TableCell();

            Paragraph p1 = new Paragraph();
            Paragraph p2 = new Paragraph();
            p1.TextAlignment = TextAlignment.Center;
            p1.FontSize = 18;
            p2.TextAlignment = TextAlignment.Right;
            p2.FontSize = 18;
            p1.Inlines.Add("ยอดขายรวมแต่ละตัวของ " + headerTxt);
            p2.Inlines.Add(string.Format("หน้าที่ {0}", pagecount + 1));

            cell1.Blocks.Add(p1);
            cell2.Blocks.Add(p2);
            tbRow.Cells.Add(cell1);
            tbRow.Cells.Add(cell2);

            tbRowGroup.Rows.Add(tbRow);
            tbHeader.RowGroups.Add(tbRowGroup);
            return tbHeader;
        }

        private static Table GetTableFroPrint(List<ShowNumberDTO> datasourceNum, double countIndex)
        {
            Table tb = new Table();
            tb.Margin = new Thickness(0, 0, 0, 0);
            tb.CellSpacing = 0;
            for (int ColCount = 0; ColCount < 5; ColCount++)
            {
                TableColumn column = new TableColumn();
                column.Width = new GridLength(columnWidth);
                tb.Columns.Add(column);
            }
            TableRowGroup tbRowGroup = new TableRowGroup();

            for (int tbRowCount = 0; tbRowCount < 20; tbRowCount++)
            {
                TableRow tbRows = new TableRow();
                for (int tableCellCount = 0; tableCellCount < 5; tableCellCount++)
                {
                    ShowNumberDTO numberSource;
                    if ((20 * tableCellCount) + tbRowCount + countIndex < datasourceNum.Count)
                    {
                        numberSource = datasourceNum[(20 * tableCellCount) + tbRowCount + int.Parse(countIndex.ToString())];


                    }
                    else
                    {
                        numberSource = new ShowNumberDTO();
                        numberSource.Number = string.Empty;

                    }
                    TableCell cell = new TableCell();



                    cell.BorderBrush = System.Windows.Media.Brushes.Black;
                    if (tbRowCount == 0 && tableCellCount == 0)
                    {
                        cell.BorderThickness = new Thickness(1, 1, 1, 0);
                    }
                    else if (tbRowCount == 0)
                    {
                        cell.BorderThickness = new Thickness(0, 1, 1, 0);
                    }
                    else if (tbRowCount == 19 && tableCellCount == 0)
                    {
                        cell.BorderThickness = new Thickness(1, 0, 1, 1);
                    }
                    else if (tbRowCount == 19)
                    {
                        cell.BorderThickness = new Thickness(0, 0, 1, 1);

                    }
                    else if (tableCellCount == 0)
                    {
                        cell.BorderThickness = new Thickness(1, 0, 1, 0);

                    }
                    else
                    {
                        cell.BorderThickness = new Thickness(0, 0, 1, 0);

                    }
                    Table tbCellValue = new Table();
                    tbCellValue.Margin = new Thickness(2);

                    TableColumn tbCellColumnValue = new TableColumn();
                    tbCellColumnValue.Width = new GridLength(74);
                    TableRowGroup tbCellRowGroupvalue = new TableRowGroup();
                    TableRow tbCellRowValue = new TableRow();

                    TableCell tbCellCellValue_Num = new TableCell();
                    TableCell tbCellCellValue_Price = new TableCell();

                    Paragraph pNum = new Paragraph();
                    Paragraph pPrice = new Paragraph();
                    pPrice.TextAlignment = TextAlignment.Right;



                    if (numberSource.Number != string.Empty)
                    {
                        if (numberSource.PriceShow == "0")
                        {
                            tbCellCellValue_Num.Foreground = new SolidColorBrush(Colors.White);
                            tbCellCellValue_Price.Foreground = new SolidColorBrush(Colors.White);
                        }

                        pNum.Inlines.Add(string.Format("{0} =", numberSource.Number));
                        pPrice.Inlines.Add(numberSource.PriceShow);
                    }


                    tbCellCellValue_Num.Blocks.Add(pNum);
                    tbCellCellValue_Price.Blocks.Add(pPrice);

                    tbCellRowValue.Cells.Add(tbCellCellValue_Num);
                    tbCellRowValue.Cells.Add(tbCellCellValue_Price);
                    tbCellRowGroupvalue.Rows.Add(tbCellRowValue);
                    tbCellValue.RowGroups.Add(tbCellRowGroupvalue);
                    tbCellValue.Columns.Add(tbCellColumnValue);
                    cell.Blocks.Add(tbCellValue);
                    tbRows.Cells.Add(cell);
                }
                tbRowGroup.Rows.Add(tbRows);
            }
            tb.RowGroups.Add(tbRowGroup);
            return tb;
        }

        public static string GetHeader(string NumberType)
        {
            string headerTxt = string.Empty;
            switch (NumberType)
            {
                case ("O3"):
                    headerTxt = "3 ตัวบน";
                    break;
                case ("U3"): headerTxt = "3 ตัวล่าง";
                    break;
                case ("T3"): headerTxt = "โต๊ด 3 บน";
                    break;
                case ("O2"): headerTxt = "2 ตัวบน";
                    break;
                case ("U2"): headerTxt = "2 ตัวล่าง";
                    break;
                case ("T2"): headerTxt = "โต๊ด 2 บน";
                    break;
                case ("O1"): headerTxt = "วิ่งบน";
                    break;
                case ("O1U"): headerTxt = "บน หลักหน่วย";
                    break;
                case ("O1D"): headerTxt = "บน หลักสิบ";
                    break;
                case ("O1H"): headerTxt = "บน หลักร้อย";
                    break;
                case ("U1"): headerTxt = "วิ่งล่าง";
                    break;
                case ("U1D"): headerTxt = "ล่าง หลักสิบ";
                    break;
                case ("U1U"): headerTxt = "ล่าง หลักหน่วย";
                    break;
                case ("TF"): headerTxt = "คู่หน้า";
                    break;
                case ("TS"): headerTxt = "คู่ถ่าง";
                    break;
                case ("FN"): headerTxt = "พวง 4 ตัว";
                    break;
                case ("FIN"): headerTxt = "5 บนโต๊ด";
                    break;

            }
            return headerTxt;
        }
        #endregion
    }
    public static class ControlExtension
    {
        public static void UpdateControlSafe(this Control control, Action code)
        {
            if (!control.Dispatcher.CheckAccess())
            {
                control.Dispatcher.BeginInvoke(code);
            }
            else
            {
                code.Invoke();
            }
        }

    }

    public static class EnumLocal
    {
        public struct NumberType
        {
            public const string Over3 = "O3";
            public const string Under3 = "U3";
            public const string Tod3 = "T3";
            public const string Over2 = "O2";
            public const string Under2 = "U2";
            public const string Tod2 = "T2";
            public const string Over1 = "O1";
            public const string Over1Unit = "O1U";
            public const string Over1Decimal = "O1D";
            public const string Over1Hundred = "O1H";
            public const string Under1 = "U1";
            public const string Under1Decimal = "U1D";
            public const string Under1unit = "U1U";
            public const string TwinFront = "TF";
            public const string TwinStretch = "TS";
            public const string FourNumber = "FN";
            public const string FiveNumber = "FIN";
        }
        public struct NumberConvertShow
        {
            public const string Over = "O";
            public const string Under = "U";
            public const string Tod = "T";
        }
    }

}
